const fs = require('fs');

// 创建一个大文件
let fileName = 'bigFile.txt';
let fd = fs.openSync(fileName, 'w');

// 随机写入一些数据
let randomData = '';
for (let i = 0; i < 10; i++) {
  randomData += Math.random().toString(36).substring(2);
}
fs.writeSync(fd, randomData);

// 关闭文件
fs.closeSync(fd);

// 计算出最多的字符
let charMap = {};
let maxChar = '';
let maxCount = 0;

let data = fs.readFileSync(fileName, 'utf8');
for (let i = 0; i < data.length; i++) {
  let char = data[i];
  if (charMap[char]) {
    charMap[char]++;
  } else {
    charMap[char] = 1;
  }
  if (charMap[char] > maxCount) {
    maxChar = char;
    maxCount = charMap[char];
  }
}

console.log(`出现最多的字符是：${maxChar}，出现次数：${maxCount}`);